package com.jerry.huihome.module.find_near_mine.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jerry.huihome.base.BaseApplication;
import com.jerry.huihome.module.find_near_mine.activity.ImageActivity;

import java.util.ArrayList;

/**
 * Created by axiang on 2016/5/14.
 */
public class ImageAdapter extends PagerAdapter{

    private final ImageActivity imageActivity;
    private final ArrayList<String> bitmapList;
    private final int positionid;

    public ImageAdapter(ImageActivity imageActivity, ArrayList<String> bitmapList, int position){
        this.imageActivity = imageActivity;
        this.bitmapList = bitmapList;
        this.positionid=position;
    }

    @Override
    public int getCount(){
        return bitmapList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position){
        ImageView imageView = new ImageView(imageActivity);
        //imageView.setImageBitmap(bitmapList.get(position));
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        container.addView(imageView);
        String url = bitmapList.get(position);
        BaseApplication.getApplication().getImageLoader().displayImage(url,imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object){
        container.removeView((View)object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object){
        return view==object;
    }
}
